import { CHANGE_FANS_LIST, CHANGE_CIRCUS_LIST } from "./constant";

import { getCircusList, getFansList, getUserById } from "@/services";

const changeCircusDataAction = (data) => ({
  type: CHANGE_CIRCUS_LIST,
  data,
});

const changeFansDataAction = (data) => ({
  type: CHANGE_FANS_LIST,
  data,
});

// 异步async函数
const asyncHandleFunc = async (data) => {
  const result = [];
  for (let item of data) {
    result.push(await getUserById(item.userId));
  }
  return result;
};

export const getCircusDataAction = (userId) => {
  return (dispatch) => {
    const circusPromise = getCircusList(userId);
    const fansPromise = getFansList(userId);
    Promise.all([circusPromise, fansPromise]).then((res) => {
      dispatch(changeCircusDataAction(res[0].data.followList));
      dispatch(changeFansDataAction(res[1].data.fanList));
    });
  };
};
